<div id="tabstrip">
    <ul>
        <li class="k-state-active">
            Danh sách đề thi
        </li>
        <li>
            Upload danh sách đề thi bằng file pdf
        </li>
    </ul>
    
    <div>
        <table class="tbl" border="1" style="table-layout:auto; width:820px;" id="tb">
            <thead> 
                <tr style="font-size:13px;"> <td>STT</td> <td>Tên đề</td> <td>Nội dung</td> <td colspan="2">Lựa chọn</td> </tr>
            </thead>
            <tbody>
                <?php
                    $i = 1;	$display = 5;
                    if( isset($_GET['page']) && (int)$_GET['page'] )
                        $page = $_GET['page'];
                    else
                    {
                        $query = mysql_query(" SELECT count(id) FROM exam WHERE name != '' ");
                        $row = mysql_fetch_array($query,MYSQLI_NUM);
                        $total_row = $row['0'];
                        if($total_row > $display)
                            $page = ceil($total_row/$display);
                        else
                            $page = 1;
                    }
                    $start = ( isset($_GET['start']) && (int)$_GET['start'] >= 0 ) ? $_GET['start'] : 0;
                    $sql = mysql_query(" SELECT id,name,content FROM exam
                                            WHERE name != '' ORDER BY name LIMIT $start,$display ");
                    if(mysql_num_rows($sql) > 0)
                    {
                        while($row = mysql_fetch_array($sql))
                        {
                            $id = $row['id'];
                            $name = $row['name'];
                            $content = $row['content'];
                            echo "<tr>";
                                echo "<td>".$i."</td>";
                                echo "<td>".ucwords($name)."</td>";
                                echo "<td> <img src='../../img/upload/exam/".$content."' width='50px' height='50px' />' </td>";
                                echo "<td> <a href='exam/edit.php?id=$id' class='option' > Sửa </a> </td>";
                                echo "<td> <a href='exam/delete.php?id=$id' class='option' onClick=\"return confirm('Bạn có thực sự muốn xóa đề thi {$name} ?')\"> Xóa </a> </td>";
                                $i++;
                            echo "</tr>";
                        }
                    }
                    else
                        echo "<tr> <td colspan='7'> Chưa có đề thi </td> </tr>";
                ?>
            </tbody>
        </table>
        <table class="nav">
            <?php
                if($page > 1)
                {
                    $prev = $start - $display ;
                    $next = $start + $display;
                    $current = ($start/$display) + 1;
                    echo "<tr>";
            
                    for($i=1 ; $i<=$page ; $i++)
                    {
                        if($current != $i)
                            echo "<td><a href='index.php?p=lst_ex&start=".($display*($i-1))."&page=$page#tb'>$i</a></td>";
                        else
                            echo " <td class='current'> $i </td> ";
                    }
        
                    echo "</tr>";
                }
            ?>
        </table>
        <b style="font-size:16px;" id="msg_import"> 
			<?php
                if(isset($_GET['msg']))
                {
                    echo $_GET['info'];
                }
            ?>
        </b>
    </div>
    <div style="height:420px;">
        <form method="post" enctype="multipart/form-data" class="frm" style="width:800px; margin-top:50px;" action="exam/add.php">
        	<h1> Upload file excel danh sách đề thi </h1>
            <p> <span style="margin:10px 10px;"> Tên đề thi </span> <input type="text" id="name" name="name" class="required" style="width:350px;" /> </p>
            <p> Vui lòng chọn File pdf cần upload <input name="file" id="file" type="file" /> </p>
            <p> (Chỉ hổ trợ file pdf) </p>
            <p style="margin:20px 0px; text-align:center;"> <input type="submit" value="Submit" class="button" /> </p>
		</form>
		
    </div>
    
</div>
